home *** CD-ROM | disk | FTP | other *** search
/ Micromanía: 150 Juegos 2010 / 150Juegos_16.iso / Shareware / Shape Smash / shape-smash.swf / scripts / mx / utils / StringUtil.as < prev   
Encoding:
Text File  |  2010-05-14  |  2.4 KB  |  101 lines

  1. package mx.utils
  2. {
  3.    import mx.core.mx_internal;
  4.    
  5.    use namespace mx_internal;
  6.    
  7.    public class StringUtil
  8.    {
  9.       mx_internal static const VERSION:String = "2.0.1.0";
  10.       
  11.       public function StringUtil()
  12.       {
  13.          super();
  14.       }
  15.       
  16.       public static function trim(param1:String) : String
  17.       {
  18.          var _loc2_:int = 0;
  19.          var _loc3_:int = 0;
  20.          _loc2_ = 0;
  21.          while(isWhitespace(param1.charAt(_loc2_)))
  22.          {
  23.             _loc2_++;
  24.          }
  25.          _loc3_ = param1.length - 1;
  26.          while(isWhitespace(param1.charAt(_loc3_)))
  27.          {
  28.             _loc3_--;
  29.          }
  30.          if(_loc3_ >= _loc2_)
  31.          {
  32.             return param1.slice(_loc2_,_loc3_ + 1);
  33.          }
  34.          return "";
  35.       }
  36.       
  37.       public static function isWhitespace(param1:String) : Boolean
  38.       {
  39.          switch(param1)
  40.          {
  41.             case " ":
  42.             case "\t":
  43.             case "\r":
  44.             case "\n":
  45.             case "\f":
  46.                return true;
  47.             default:
  48.                return false;
  49.          }
  50.       }
  51.       
  52.       public static function substitute(param1:String, ... rest) : String
  53.       {
  54.          var _loc3_:uint = 0;
  55.          var _loc4_:Array = null;
  56.          var _loc5_:int = 0;
  57.          _loc3_ = uint(rest.length);
  58.          if(_loc3_ == 1 && rest[0] is Array)
  59.          {
  60.             _loc4_ = rest[0] as Array;
  61.             _loc3_ = _loc4_.length;
  62.          }
  63.          else
  64.          {
  65.             _loc4_ = rest;
  66.          }
  67.          _loc5_ = 0;
  68.          while(_loc5_ < _loc3_)
  69.          {
  70.             param1 = param1.replace(new RegExp("\\{" + _loc5_ + "\\}","g"),_loc4_[_loc5_]);
  71.             _loc5_++;
  72.          }
  73.          return param1;
  74.       }
  75.       
  76.       public static function trimArrayElements(param1:String, param2:String) : String
  77.       {
  78.          var _loc3_:Array = null;
  79.          var _loc4_:int = 0;
  80.          var _loc5_:int = 0;
  81.          if(param1 != "" && param1 != null)
  82.          {
  83.             _loc3_ = param1.split(param2);
  84.             _loc4_ = int(_loc3_.length);
  85.             _loc5_ = 0;
  86.             while(_loc5_ < _loc4_)
  87.             {
  88.                _loc3_[_loc5_] = StringUtil.trim(_loc3_[_loc5_]);
  89.                _loc5_++;
  90.             }
  91.             if(_loc4_ > 0)
  92.             {
  93.                param1 = _loc3_.join(param2);
  94.             }
  95.          }
  96.          return param1;
  97.       }
  98.    }
  99. }
  100.  
  101.